<template>
  <div>
    <p>count值为:{{count}}</p>
    <button @click="add">+1</button>
  </div>
</template>

<script>
export default {
  name:'MyCount',
  // 声明自定义事件
  emits:['countChange'],
  data(){
    return{
      count:0
    }
  },
  methods:{
    add(){
      this.count++,
      // 调用$emit方法出发了countChange自定义事件
      this.$emit('countChange',this.count)
    }
  }
}
</script>

<style lang="less" scoped>

</style>